//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <string.h>
#include <elatypes.h>

int __cdecl wcscmp(const wchar_t* str1, const wchar_t* str2)
{
    register int result;

#ifdef _GNUC

#if defined(_x86)
    int temp0, temp1;
    ASM("1:"
        "lodsw;"
        "scasw;"
        "jne 2f;"
        "testw %%ax,%%ax;"
        "jne 1b;"
        "xorl %%eax,%%eax;"
        "jmp 3f;"
        "2:"
        "sbbl %%eax,%%eax;"
        "orw $1,%%ax;"
        "3:"
        :"=a"(result), "=S" (temp0), "=D" (temp1)
        :"1" (str1), "2" (str2));

    return result;
#endif    //if defined(_x86)

//#if defined(_arm)
//    asm __volatile__(
//        "1:\tldrh r2, [r0], #2\n\t"
//        "ldrh r3, [r1], #2\n\t"
//        "sub r4, r2, r3\n\t"
//        "cmp r4, #0\n\t"
//        "bne 2f\n\t"
//        "mov r3, r3, lsl #16\n\t"
//        "mov r3, r3, lsr #16\n\t"
//        "cmp r3, #0\n\t"
//        "bne 1b\n"
//        "2:\tmov %0, r4\n\t"
//        :"=r"(result)
//        ::"r2", "r3", "r4");
//
//    return result;
//#endif    //if defined(_arm)

#endif    //ifdef _GNUC

    do {
        result = *str1 - *str2;
        str1++;
    } while (result == 0 && *str2++!= '\0');

    return result;
}
